<?php
namespace app\api\controller\wsgoods;
class Ordercart extends Base{
    public function __construct() {
        parent::__construct();
        $this->checkLogin();
    }
    /**
     * 添加购物车
     */
    public function edit(){
        $d = $this->post();
        $rule = [
            'goods_price_id'=>'require',
            'nums'=>'require|integer',
        ];
        $msg = [
            'goods_price_id.require' => '商品规格ID不能为空',
            'nums.require' => '数量不能为空',
        ];
        check($rule,$msg,$d);
        $rs = m("OrderCart","c")->edit($this->userinfo['id'],$d['goods_price_id'], $d['nums']);
        if($rs){
            suc();
        }else{
            err(m("OrderCart","c")->getError());
        }
    }

    /**
     * 用户购物车
     */
    public function lists(){
        $d = $this->post();
        $rule = [];
        $msg = [];
        check($rule,$msg,$d);
        $rs = m("OrderCart","c")->lists($this->userinfo['id']);
        suc($rs);
    }

}
?>
